import request from '@/utils/request'
import {proxyPrefix} from '../utils/index'
import {transformFromObj} from '../utils/index'

export function getUserList(params) {
  return request({
    url: proxyPrefix +'/user/list',
    method: 'post',
    data: params
  })
}

export function create(params) {
  return request({
    url: proxyPrefix +'/user/create',
    method: 'post',
    data: params
  })
}

export function detail(id) {
  return request({
    url: proxyPrefix +'/user/detail',
    method: 'get',
    params: {id}
  })
}

export function getUserInfo(token) {
  const data = {
    token: token
  }
  return request({
    url: proxyPrefix +'/user/tokenUserInfo',
    method: 'post',
    data
  })
}

export function batchDel(id) {
  return request({
    url: proxyPrefix +'/user/batchDel',
    method: 'get',
    params: {id: id}
  })
}

export function updatePass(params) {
  console.info(params)
  return request({
    url: proxyPrefix +'/user/updatePwd',
    method: 'post',
    data: params,
    transformRequest: [
      function (params) {
        let ret = ''
        for (let it in params) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(params[it]) + '&'
        }
        ret = ret.substring(0, ret.lastIndexOf('&'));
        return ret
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}
